/**
 * 
 */
package edu.arizona.bio5.onto.decomposition.persistent;

import java.io.Reader;

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.ReaderDocumentSource;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;


/**
 * @author Pavel Klinov
 *
 */
public abstract class AbstractAtomLoader implements AtomLoader {

	@Override
	public void load(PersistentAtom atom) throws ADPersistenceException {
		Reader ontoReader = getOntologySourceReader(atom);
		OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
		
		try {
			OWLOntology atomOntology = mgr.loadOntologyFromOntologyDocument(new ReaderDocumentSource(ontoReader));
			
			atom.setAxiomSet(atomOntology.getAxioms());
			
		} catch (OWLOntologyCreationException e) {
			throw new ADPersistenceException(e);
		}
	}

	protected abstract Reader getOntologySourceReader(PersistentAtom atom) throws ADPersistenceException;
}
